#ifndef RENDERER_H
#define RENDERER_H

#include "Framework.h"
#include "Shader.h"
#include <assimp.h>
#include "Camera.h"
#include "AIEngine.h"
#include "DisplayCharacter.h"

class Renderer {
public:
	Renderer(Camera *camera_, AIEngine* aiEngine_);
	void loadTextureData(const aiScene *scene);
        void loadParticleTextures();
	void renderAllScenes();
	void disableVertexAttributeArrays();
	void setCurrentShader(Shader *shader) { currentShader = shader; }
	Shader* getPhongShader() { return phong; }
	Shader* getPhongToonShader() { return phongToon; }
	Shader* getCurrentShader() { return currentShader; }
	Shader* getNormalColShader() { return normalCol; }
	Shader* getTextureDrawShader() { return textureDraw; }
	Shader* getShadowShader() { return shadow; }
	Shader* getOutlineShader() { return outline; }
	Shader* getOutlineFilterShader() { return outlineFilter; }
        Shader* getOutlinePlusSceneShader() { return outlinePlusScene; }
        Shader* getThicknessShader() { return thickness; }
        Shader* getPhoneToonShader() { return phongToonShadow; }
        Shader* getParticleShader(){ return particle; }

	const aiScene* getScene(int i) { return scenes.at(i); }
	bool getDrawShadows() { return drawShadows; }
	void setDrawShadows(bool val) { drawShadows = val; }
	void setLightTextureMatrix();

	void renderAllParticles(float elapsedTime);

	sf::String* getStatusStr() { return statusString; }

	sf::Image *fireTexture;
	sf::Image *sparkTexture;

private:
	void loadAssets();
	void setMeshData(aiMesh *mesh, aiMatrix4x4 *model, aiVector3D *vertices);
	void setTextures(aiMesh *mesh, const aiScene *scene);
	void setMaterial(aiMesh *mesh, const aiScene *scene);
	void recursive_render(const aiScene *scene, const aiNode* nd, aiMatrix4x4 model, bool drawBones);

	std::map<std::string, sf::Image*> textures;
	Shader *phong;
	Shader *phongToon;
	Shader *currentShader;
	Shader *normalCol;
	Shader *textureDraw;
	Shader *shadow;
	Shader *outline;
	Shader *outlineFilter;
	Shader *outlinePlusScene;
        Shader *thickness;
        Shader *phongToonShadow;
	Shader *particle;

	AIEngine *aiEngine;
	Camera *camera;
	// This creates an asset importer using the Open Asset Import library.
	// It automatically manages resources for you, and frees them when the program
	// exits.
	std::vector<Assimp::Importer*> importers;
	std::vector<const aiScene*> scenes;
	std::vector<const aiScene*> secondaryEnemies;
	std::vector<char*> modelPaths;

	bool drawShadows;
	GLdouble bias[16];
	double lightModelView[16];
	double lightProjection[16];
	DisplayCharacter *displayCharacterIdleRenderer;
	DisplayCharacter *displayCharacterRunningRenderer;
	DisplayCharacter *currentDisplayCharacterRenderer;
	std::vector<aiVector3D> *resultPos;
	sf::Font *font;
	sf::String *statusString;

};

#endif
